from django.db import models


# Create your models here.

# 一对多关系处理   在多的一方 添加外键
class Publisher(models.Model):
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=100)

    class Meta:
        db_table = 'publisher'


class Book(models.Model):
    name = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    # 外键约束  publisher_id     Publisher    id  PROTECT 受保护
    publisher = models.ForeignKey(Publisher, on_delete=models.PROTECT)

    class Meta:
        db_table = 'book'
